package com.erlinyou.travel.dao.repository.user;


import java.util.List;
import java.util.Map;

import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.repository.Query;

import com.erlinyou.base.dao.BaseRepository;
import com.erlinyou.travel.model.user.TUser;

public interface TUserRepository extends BaseRepository<TUser, Long> {
	public TUser findByUserid(Long userid);
	public TUser findTopByPhone(String phone,Sort sort);
//	/**
//	 * 通过用户ID查询,匹配到ids的好友
//	 * @param ids
//	 * @param username
//	 * @return
//	 */
//	@Query(value="SELECT t.* from erlinyou_im.ofroster r LEFT JOIN etravel.tuser t ON r.jid = t.userid where r.username = ?2 AND r.sub=3 AND FIND_IN_SET(t.userid,?1)>0",nativeQuery=true)
//	public List<TUser> selectByids(String ids,String username);

	@Query(value="SELECT * from tuser WHERE FIND_IN_SET(userid,?1)>0",nativeQuery=true)
	public List<TUser> selectByids(String userids);
	
	@Query(value="SELECT t.userid,t.image,t.nickName from tuser t where FIND_IN_SET(userid,?1) AND nickName LIKE CONCAT('%',?2,'%') LIMIT 0,10",nativeQuery=true)
	public List<Map<String, Object>> searchByContacts(String Ids, String nickName);
	@Query(value="SELECT nickName,image,userid from tuser where nickName LIKE CONCAT(?1,'%') LIMIT ?2,?3",nativeQuery=true)
	public List<Map<String, Object>> searchByboobuz(String nickName, int startPage, int rows);
	@Query(value="SELECT userid,image,nickName from tuser where FIND_IN_SET(userid,?1)",nativeQuery=true)
	public List<Map<String, Object>> selectByUserid(String ids);
	
	@Query(value="SELECT userid,phone,image,nickName,gender from tuser WHERE FIND_IN_SET(phone,?1)",nativeQuery=true)
	public List<Map<String, Object>> getInfoByPhone(String phones);
	@Query(value="SELECT gender from tuser WHERE userid = ?1",nativeQuery=true)
	public int selectGenderByUsreId(Long userId);
	
	@Query(value="SELECT userid,phone,image,nickName,gender from tuser WHERE gender!=?2 and userid not in (?1) AND phone != '' AND image != '' AND nickName != '' ORDER BY createDate DESC LIMIT ?3,10",nativeQuery=true)
	public List<Map<String, Object>> randomUserInfo(String ids, int gender, int page);
	
}
